package com.yyx.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yyx.server.pojo.Employee;
import com.yyx.server.service.EmployeeService;
import com.yyx.server.vo.PageVo;
import com.yyx.server.vo.ResultVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author YongXin
 * @date Created in 2021/8/12 20:16
 */
@RestController
@RequestMapping("/salary/sobcfg")
public class SalaryEmpController {
    @Autowired
    private EmployeeService employeeService;

    @ApiOperation("分页获取所有员工账套")
    @GetMapping("/")
    public PageVo getEmpWithSalary(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer pageSize){
        IPage<Employee> page = employeeService.getEmpWithSalary(currentPage, pageSize);
        return new PageVo(page.getTotal(),page.getRecords());
    }
    @ApiOperation("通过工号查询员工账套")
    @GetMapping("/getEmpWithSalaryByWorkId")
    public PageVo getEmpWithSalaryByWorkId(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam String workId){
        IPage<Employee> page = employeeService.getEmpWithSalaryByWorkId(currentPage, pageSize,workId);
        return new PageVo(page.getTotal(),page.getRecords());
    }

    @ApiOperation("更新员工账套")
    @PutMapping("/")
    public ResultVo updEmpWithSalary(Integer eid,Integer sid){
        if (employeeService.update(new UpdateWrapper<Employee>().set("salary_id",sid).eq("id",eid))){
            return ResultVo.success("更新成功");
        }
        return ResultVo.error("更新成功");
    }
}
